from signal_module import analysis_module
from signal_testtype import analysis_detail
from signal_total import analysis_total
from virsul_step1 import virsul_step1
from report_step3 import get_report
import tos
import time

# Access key 和 Secret key 可在用户火山引擎账号中查找
ak = "AKLTMmFmMzVmNmY5ZDEyNDNmNWEyZTU2MDM3Y2EzMDJlZTk"
sk = "WVdNeFpXRXdNekV4Tm1ZME5EZGxPRGc0TUdFNE1HWXdNV1ZqTkdNNU9HRQ=="
# your endpoint 和 your region 填写Bucket 所在区域对应的Endpoint。# 以华北2(北京)为例，your endpoint 填写 tos-cn-beijing.volces.com，your region 填写 cn-beijing。
endpoint = "tos-cn-beijing.volces.com"
region = "cn-beijing"

def upload(bucket_name,object_key,file_name):
    try:
        # 创建 TosClientV2 对象，对桶和对象的操作都通过 TosClientV2 实现
        client = tos.TosClientV2(ak, sk, endpoint, region)
        # 将本地文件上传到目标桶中
        # file_name为本地文件的完整路径。
        client.put_object_from_file(bucket_name, object_key, file_name)
    except tos.exceptions.TosClientError as e:
        # 操作失败，捕获客户端异常，一般情况为非法请求参数或网络异常
        print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))
    except tos.exceptions.TosServerError as e:
        # 操作失败，捕获服务端异常，可从返回信息中获取详细错误信息
        print('fail with server error, code: {}'.format(e.code))
        # request id 可定位具体问题，强烈建议日志中保存
        print('error with request id: {}'.format(e.request_id))
        print('error with message: {}'.format(e.message))
        print('error with http code: {}'.format(e.status_code))
    except Exception as e:
        print('fail with unknown error: {}'.format(e))


if __name__ == '__main__':
    pt_date = '20231205'
    pt_hour = '19'
    savepath = '/data/code/'
    #生成module数据：
    analysis_module(savepath,pt_date,pt_hour)
    #生成testtype数据
    analysis_detail(savepath, pt_date, pt_hour)
    #生成total数据：
    analysis_total(savepath, pt_date, pt_hour)
    #生成图片
    virsul_step1(pt_date, pt_hour, savepath)
    #生成报告：
    get_report(savepath, pt_date, pt_hour)
    #上传报告
    bucket_name="neta-simulation-data"
    report_name = '数据一致性仿真测试评测报告_' + pt_date + '_' + pt_hour+".pdf"
    object_key="orin_signal_check/"+pt_date+"/"+pt_hour+"/"+report_name
    file_name=savepath+report_name
    upload(bucket_name, object_key, file_name)